package cn.nexd.app;

import android.content.Context;
import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.io.IOException;
import java.lang.Thread.UncaughtExceptionHandler;

import cn.nexd.app.util.DateUtil;
import cn.nexd.app.util.FileUtil;

/**
 * Created by wangxu on 16/3/24.
 */
public class MyUncaughtExceptionHandler implements UncaughtExceptionHandler {
    Context context;

    public MyUncaughtExceptionHandler(Context applicationContext) {
        context = applicationContext;
    }

    @Override
    public void uncaughtException(Thread thread, final Throwable ex) {
        Log.d("MyExceptionHHHH", "出错了");
        new Thread(new Runnable() {
            @Override
            public void run() {


                String path = Environment.getExternalStorageDirectory().getPath() + File.separator +
                        "nexd/error/" + DateUtil.getCurrentByType(DateUtil.YYYYMMDD)
                        + File.separator + DateUtil.getCurrentByType(DateUtil.YYYYMMDDhhmmss) + ".err";
                try {
                    FileUtil.writeFile(path, ex.getMessage());
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }).start();

    }
}
